package com.serialization.demo3;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

import com.serialization.demo1.Worm;

/**
 * 保存对象状态
 * 
 * @author Administrator
 *
 */
public class Test {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws FileNotFoundException,
			IOException, ClassNotFoundException {
		List<Class<? extends Shape>> shapeTypes = new ArrayList<Class<? extends Shape>>();
		shapeTypes.add(Circle.class);
		shapeTypes.add(Square.class);

		List<Shape> shapes = new ArrayList<Shape>();
		for (int i = 0; i < 5; i++) {
			shapes.add(Shape.randomFactory());
		}
		for (int i = 0; i < 5; i++) {
			shapes.get(i).setColor(Shape.GREEN);
		}

		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
				"cad.out"));
		out.writeObject(shapeTypes);
		out.writeObject(shapes);
		System.out.println(shapes);
	}

}
